package dao;

import java.util.LinkedList;
import java.util.List;
import entities.Administrator;
public class AdministratorDAO 
{

	private static final AdministratorDAO instance = new AdministratorDAO();
	private List<Administrator> administrators;
	
	private AdministratorDAO(){
		administrators = new LinkedList<Administrator>();
		Administrator admin = null;
		
		admin = Administrator.newInstance("ferdis", "ferdis@hotmail.com", "Manuel", "Lopez", "ferman");
		administrators.add(admin);
		admin = Administrator.newInstance("dorea", "doris23@gmail.com", "Dorca", "Salazar", "jljh877");
		administrators.add(admin);
		admin = Administrator.newInstance("solt", "forwm@hotmail.com", "Lord", "Jore", "h97873r");
		administrators.add(admin);
		admin = Administrator.newInstance("Mors", "mors@gmail.com", "Mort", "Korte", "8041nmn");
		administrators.add(admin);
		admin = Administrator.newInstance("joawq", "1qade@yahoo.com", "Jade", "Crist", "849nma");
		administrators.add(admin);
		admin = Administrator.newInstance("Cristofel", "Cristofel@hotmail.com", "Cristofel", "Maer", "98amdl");
		administrators.add(admin);
		admin = Administrator.newInstance("soper", "soper98@hotmailc.com", "Dino", "Ren", "o098u2");
		administrators.add(admin);
		admin = Administrator.newInstance("polasre", "polasre@gmail.com", "Marcos", "Polo", "marpol1");
		administrators.add(admin);
		admin = Administrator.newInstance("yera", "yera@yahoo.com", "Yesto", "Forde", "uihd98f");
		administrators.add(admin);
		admin = Administrator.newInstance("pow08", "pow08@hotmail.com", "Power", "Line", "mma91dgf");
		administrators.add(admin);
		admin = Administrator.newInstance("poqz", "pozad@hotmail.com", "Poz", "Showeas", "jka811");
		administrators.add(admin);
		admin = Administrator.newInstance("marra", "mart@hotmail.com", "Martin", "lname", "ugh0012");
		administrators.add(admin);
		admin = Administrator.newInstance("admin", "admin1@yahoo.com", "Admin", "Proy", "adminis");
		administrators.add(admin);
		admin = Administrator.newInstance("admin2", "admin2@yahoo.com", "Admin2", "Proy2", "adminis2");
		administrators.add(admin);
		admin = Administrator.newInstance("admin3", "admin3@yahoo.com", "Admin3", "Proy3", "adminis3");
		administrators.add(admin);
	}
	
	public static AdministratorDAO getInstance() {
		return instance;
	}

	public synchronized Administrator findAdministrator(String username) {
		Administrator result = null;
		for (Administrator s : administrators){
			if (s.getUserID().equals(username)){
				result = s;
			}
		}
		return result;
	}

	public synchronized void addAdministrator(Administrator obj) throws RecordDuplicateException{
		if (findAdministrator(obj.getUserID()) != null){
			throw new RecordDuplicateException("Customer with id: " + obj.getUserID() + " is already in the db.");
		}
		else {
			administrators.add(obj);
		}
	}
	public List<Administrator> getListAdministrators(){
		return administrators;
	}
}
